<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
          "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>QUnit for 'jws.js' IntDate class methods</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />

<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="qunit.js"></script>

<script language="JavaScript" type="text/javascript" src="../ext/json-sans-eval.js"></script>
<script language="JavaScript" type="text/javascript" src="../src/base64x-1.1.js"></script>
<script language="JavaScript" type="text/javascript" src="../src/jws-3.3.js"></script>

<script type="text/javascript">
$(document).ready(function(){

test("abs(new Date() - getNow()) < 3", function() {
  expect(1);
  var tNow1 = KJUR.jws.IntDate.getNow();
  var tNow2 = ~~(new Date() / 1000);
  var delta = Math.abs(tNow2 - tNow1);
  equal(delta < 3, true, "");
});

test("abs(new Date() - get('now') < 3", function() {
  expect(1);
  var tNow1 = KJUR.jws.IntDate.get('now');
  var tNow2 = ~~(new Date() / 1000);
  var delta = Math.abs(tNow2 - tNow1);
  equal(delta < 3, true, "");
});

test("60*60-3 < get('now + 1hour') - get('now') < 60*60+3", function() {
  expect(2);
  var tNow1 = KJUR.jws.IntDate.get('now');
  var tNow2 = KJUR.jws.IntDate.get('now + 1hour');
  var delta = tNow2 - tNow1
  equal(delta < 60 * 60 + 3, true, "");
  equal(delta > 60 * 60 - 3, true, "");
});

test("getZulu(20130828042500Z) = 1377663900", function() {
  equal(KJUR.jws.IntDate.getZulu('20130828042500Z'), 1377663900, "");
});

test("getZulu(130828042500Z) = 1377663900", function() {
  equal(KJUR.jws.IntDate.getZulu('130828042500Z'), 1377663900, "");
});


test("getZulu(19700101000000Z)", function() {
  equal(KJUR.jws.IntDate.getZulu('19700101000000Z'), 0, "1");
});

test("getZulu(700101000000Z)", function() {
  equal(KJUR.jws.IntDate.getZulu('700101000000Z'), 0, "1");
});

test("intDate2UTCString(getZulu(19700201000000Z))=Thu, 01 Jan 1970 00:00:00 GMT", function() {
  equal(KJUR.jws.IntDate.intDate2UTCString(KJUR.jws.IntDate.getZulu('19700101000000Z')), "Thu, 01 Jan 1970 00:00:00 GMT", "1");
});

test("intDate2Zulu(0)==19700101000000Z", function() {
  equal(KJUR.jws.IntDate.intDate2Zulu(0), "19700101000000Z", "1");
});

});
</script>
  
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">test markup</div>
<a href="index.html">TEST INDEX</a> | 
<a href="qunit-do-jws-sign.html">sign/verify</a> | 
<a href="qunit-do-jws-sign-slow.html">sign/verify slow</a> | 
<a href="qunit-do-jws-intdate.html">IntDate</a> | 
</body>
</html>
